package com.smt.ejb3.tutoria.client;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.smt.ejb3.tutoria.entitybean.many2one.Company;
import com.smt.ejb3.tutoria.entitybean.many2one.Employee;
import com.smt.ejb3.tutoria.service.MappingService;

public class EmployeeClient {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Company company = new Company();
		company.setName("IBM");
		
		Employee emp = new Employee();
		emp.setName("Old Sun");
		emp.setCompany(company);
		
		Employee emp2 = new Employee();
		emp2.setName("Old Change");
//		emp2.setCompany(company);
		
		
		try {
			InitialContext ctx = new InitialContext();

			MappingService service = (MappingService) ctx
					.lookup("MappingServiceImpl/remote");
			/*emp = service.saveEmployee(emp);
			System.out.println(emp.getId()+ " "+emp.getName());
			company = emp.getCompany();
			emp2.setCompany(company);
			service.saveEmployee(emp2);*/
			
			emp = new Employee();
			emp.setId(1);
			emp.setName("Old xu");
			emp.setCompany(company);
			
			service.saveEmployee(emp);
			
//			service.testSave();
		} catch (NamingException ex) {
			ex.printStackTrace();
		}
	}
}
